//
//  HPCustomerInfoAddViewController.m
//  HappyPenguin
//
//  Created by zhuangyihang on 1/27/16.
//  Copyright © 2016 zhuangyihang. All rights reserved.
//

#import "HPCustomerInfoAddViewController.h"
#import "KSViewPagerView.h"
#import "HPHttpInfoItemRequest.h"

@interface HPCustomerInfoAddViewController()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) KSViewPagerView *pagerView;
@property (nonatomic, strong) UIScrollView *mainScrollView;

@end

@implementation HPCustomerInfoAddViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    [self addBackButton:@selector(back)];
    [self setBaseNavigationBarTitle:@"添加"];
    
    [self setupPanel];
    
    HPHttpInfoItemRequest *reqeust = [[HPHttpInfoItemRequest alloc] init];
    reqeust.responseBlock = ^(HPHttpInfoItemResponse *response, HttpError *error){
        if (error) {
            
        }else{
            
        }
    };
    [reqeust send];
}

- (void)setupPanel{
    WS(ws);
    
    self.pagerView = [[KSViewPagerView alloc] initWithArray:@[@"基本资料",@"基本资料",@"基本资料",@"基本资料"]];
    [self.baseContentView addSubview:self.pagerView];
    self.pagerView.backgroundColor = [UIColor whiteColor];
    [self.pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.top.width.equalTo(self.baseContentView);
        make.height.equalTo(@40);
    }];
    
    [self.pagerView setActiveColor:[UIColor colorWithRGB:0x4fbcff]];
    [self.pagerView setInactiveColor:[UIColor colorWithRGB:0xafafaf]];
    [self.pagerView setTitleFont:[UIConstants getFont:15]];
    self.pagerView.click = ^(KSViewPagerView*v, NSNumber *index){
        [ws.mainScrollView setContentOffset:CGPointMake([index intValue]*v.width, 0) animated:YES];
    };
    
    [self.pagerView setCursorPosition:0];
    
    CGFloat screenWidth  = [UIScreen mainScreen].bounds.size.width;
    
    UIScrollView *scrollView = [UIScrollView new];
    [self.baseContentView addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pagerView.mas_bottom);
        make.width.bottom.centerX.equalTo(self.baseContentView);
    }];
    scrollView.pagingEnabled = YES;
    self.mainScrollView = scrollView;
    scrollView.contentSize = CGSizeMake(4*screenWidth, 0);
    scrollView.delegate = self;
    
    for (int i = 0; i < 4; i++) {
        UITableView *tableView = [UITableView new];
        tableView.delegate = self;
        tableView.dataSource = self;
        [scrollView addSubview:tableView];
        tableView.tableFooterView = [UIView new];
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(i * screenWidth);
            make.width.equalTo(self.baseContentView);
            make.height.centerY.equalTo(scrollView);
        }];
    }
}

#pragma mark - Click
- (void)back{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - UIScrollView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    float page = scrollView.contentOffset.x/scrollView.width;
    [self.pagerView setCursorPosition:page];
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"CustomerInfoAddCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.textLabel.text = @"身份证号";
    
    return cell;
}
@end
